#import "NSAttributedString+SMRAdditions.h"


@implementation NSAttributedString (SMRAdditions)

-(NSAttributedString *)smrAttributedStringByTrimmingCharactersInSet:(NSCharacterSet *)set {
	NSRange frontRange, endRange, finalRange;
	NSCharacterSet *invertedSet = [set invertedSet];
	
	// Find the range of the first character you want to keep
	frontRange = [[self string] rangeOfCharacterFromSet:invertedSet];
	// Find the range of the last character you want to keep
	endRange = [[self string] rangeOfCharacterFromSet:invertedSet options:NSBackwardsSearch];
	
	if (frontRange.location == NSNotFound) 
		return [[[NSAttributedString alloc] initWithString:@""] autorelease];
	
	finalRange = NSMakeRange(frontRange.location, NSMaxRange(endRange) -
							 frontRange.location);
	
	return [self attributedSubstringFromRange:finalRange];
}

-(NSRange)smrFullRange {
	return NSMakeRange(0, [self length]);
}

@end
